package com.tanhua.dubbo.mongo.api;

import com.tanhua.model.mongo.FocusUser;
import com.tanhua.model.vo.ErrorResult;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.ibatis.builder.BuilderException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@DubboService
public class FocusUserApiImpl implements FocusUserApi {

    @Autowired
    private MongoTemplate mongoTemplatel;




    //保存关注信息
    public void saveFocus(FocusUser focusUser) {

            mongoTemplatel.save(focusUser);


    }

    //视频用户关注 - 取消
    public void userUnFocus(Long userId, Long focusId) {

        Criteria criteria = Criteria.where("userId").is(userId).and("focusId").is(focusId);
        Query query = Query.query(criteria);

        mongoTemplatel.remove(query,FocusUser.class);

    }

    //根据id查询用户是否存在
    public Boolean findById(Long userId, Long focusId) {
        Criteria criteria = Criteria.where("userId").is(userId)
                .and("focusId").is(focusId);
        Query query = Query.query(criteria);
        boolean exists = mongoTemplatel.exists(query, FocusUser.class);
        return exists;
    }
}
